﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PARK
{
    /// <summary>
    /// 时间工具类
    /// </summary>
    public static class QRcodeUtil
    {
        /// <summary>
        /// 时间戳计时开始时间
        /// </summary>
        private static DateTime timeStampStartTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        /// <summary>
        /// DateTime转换为10位时间戳（单位：秒）
        /// </summary>
        /// <param name="dateTime"> DateTime</param>
        /// <returns>10位时间戳（单位：秒）</returns>
        static long DateTimeToTimeStamp(DateTime dateTime)
        {
            return (long)(dateTime.ToUniversalTime() - timeStampStartTime).TotalSeconds;
        }
        public static string CreateQRcode(string cardType, string CardNo, DateTime ExpiryEndDate)
        {
            //卡类型（2位长度）+时间戳(10位长度）+卡号     使用 sm4_crypt_ecb  加密 
            var _str = cardType.PadLeft(2, '0') + DateTimeToTimeStamp(ExpiryEndDate).ToString() + CardNo;
            return _str;
        }
    }
}
